package cn.hyman.producer;

import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Topic;
import java.util.UUID;

@Component
public class TopicProducer {

    @Autowired
    private Topic activeMQTopic;

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    //发送Queue的方法
    public void producerMsg() {
        jmsMessagingTemplate.convertAndSend(activeMQTopic, "*******producerTopicMsg*******" + UUID.randomUUID().toString());
    }

    //发送Queue的方法
    @Scheduled(fixedDelay = 3000L)
    public void producerMsgScheduled() {
        jmsMessagingTemplate.convertAndSend(activeMQTopic, "*******producerTopicMsgScheduled*******" + UUID.randomUUID().toString());
        System.out.println("producerMsgScheduled send---");
    }


}
